package com.luoxiang.socialandroid.dialog

import android.content.Context
import android.text.Editable
import android.text.TextWatcher
import com.luoxiang.socialandroid.R
import com.luoxiang.socialandroid.databinding.DialogBatchgreetingBinding
import com.luoxiang.socialandroid.databinding.DialogTipBinding
import com.luoxiang.socialandroid.databinding.DiaogEditBinding
import com.lxj.xpopup.impl.FullScreenPopupView

class EditDialog(context: Context) : FullScreenPopupView(context) {
    private lateinit var mViewBinding: DiaogEditBinding
    private var title: String? = null
    private var edittitle: String?=null
    override fun getImplLayoutId() = R.layout.diaog_edit
    private var onCancelClickListener: (() -> Unit)? = null
    private var onConfirmClickListener: ((String) -> Unit)? = null
    private var edtTianJia: (() -> String)? = null
    override fun onCreate() {
        super.onCreate()

        mViewBinding = DiaogEditBinding.bind(popupImplView)
        mViewBinding.viewCancel.setOnClickListener { onCancelClickListener?.invoke() }
        mViewBinding.viewConfirm.setOnClickListener { onConfirmClickListener?.invoke(mViewBinding.edtTianJia.text.toString()) }

        mViewBinding.textView25.text = title
        mViewBinding.edtTianJia.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }

            override fun afterTextChanged(s: Editable?) {
                mViewBinding.textView26.text =
                    mViewBinding.edtTianJia.text.length.toString() + "/30"
            }

        })
    }

    fun setTitle(title: String) {
        this.title = title//设置标题
    }

    fun setOnCancelClickListener(onCancelClickListener: () -> Unit) {
        this.onCancelClickListener = onCancelClickListener
    }

    fun setOnConfirmClickListener(onConfirmClickListener: (String) -> Unit) {
        this.onConfirmClickListener = onConfirmClickListener
    }

}